# -*- coding: utf-8 -*-
from settings.ConcilerManage import Controllers
import json

# 创建hpa


class samples(Controllers):

    def Create(self, event):

        print("创建")
        print(event["object"])
        port = event["object"]["spec"]["port"]
        targetPort = event["object"]["spec"]["targetPort"]

        name = event["object"]["metadata"]["name"]
        uid = event["object"]["metadata"]["uid"]
        body = {
            "kind": "Service",
            "spec": {
                "ports": [
                    {
                        "targetPort": port,
                        "protocol": "TCP",
                        "port": targetPort
                    }
                ],
                "selector": {
                    "app": "test"
                }
            },
            "apiVersion": "v1",
            "metadata": {
                "namespace": self.CRD_NAMESPACE,
                "name": "test-svc"

            }
        }

        self.load_config()
        CoreV1Api = self.client.CoreV1Api()

        print("load===",body)
        CoreV1Api.create_namespaced_service(
            namespace=self.CRD_NAMESPACE, body=body, async_req=True)
